
package com.oahcfly.chgame.egret.ui;

import java.util.HashMap;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.oahcfly.chgame.core.Chao;

/** 资源管理
 * 
 * @author haocao */
public class ERes {

	private static HashMap<String, String> resourceMap = new HashMap<String, String>();

	/** 获取纹理
	 * 
	 * @param name
	 * @return */
	public static Texture getResTexture (String name) {
		String url = resourceMap.get(name);
		if (url == null) {
			Gdx.app.error("ERes", "can not find " + name + " in resourceMap...");
		}
		return Chao.game.getTexture(url);
	}

	/** 加载资源
	 * 
	 * @param name "gold_png"
	 * @param url "game/gold.png" */
	public static void loadRes (String name, String url) {
		resourceMap.put(name, url);
	}

	public static String getResUrl (String name) {
		return resourceMap.get(name);
	}

	/** 释放资源 */
	public static void disposeRes () {
		Gdx.app.log("ERES", "dispose");
		for (String url : resourceMap.values()) {
			if (Chao.game.getAssetManager().isLoaded(url)) {
				Chao.game.getAssetManager().unload(url);
			}
		}
		resourceMap.clear();
	}

	public static HashMap<String, String> getResMap () {
		return resourceMap;
	}
}
